Continuous positive functions on metric spaces

Let $Y$ be a metric space, with $X$ a closed subset of $Y$. For any open neighbourhood $U$ of $X$ in $Y$, there exists a positive continuous function $f$ on $X$ such that, if $x \in X$, and $d(x,y) < f(x)$, then $y \in U$.

Proof

Take the function $f(x) = d(x, Y \setminus U)$. Then $|f(x) - f(x')| \leq d(x,x')$, so $f$ is continuous and positive.

Proof is from C.T.C. Wall's Differential Topology